#include <iostream>
using namespace std;
int a(int b) {
	if (b < 0) {
		return -b;
	}
	else {
		return b;
	}
}
int main() {
	int length;
	cin >> length;
	int arr[1000][10] = { 0 };
	for (int i = 0; i < length; i++){
		for (int j = 0; j < 3; j++) {
			cin >> arr[i][j];
			arr[i][3] += arr[i][j];
		}
	}
	int t = 0;
	for (int i = 1; i < length; i++) {
		for (int j = 0; j<i; j++) {
      int tmp = 1;
			for (int h = 0; h < 3; h++) {
				if (a(arr[i][h] - arr[j][h]) > 5) {
					tmp = 0;
				}
			}
      if (a(arr[i][3] - arr[j][3]) > 10) {
          tmp = 0;
      }
      if (tmp == 1) {
          t++;
      }
		}
	}
	cout << t << endl;
	return 0;
}
